<header role="banner" class="header bg--highest"
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:s="http://jboss.org/schema/seam/taglib"
  xmlns:rich="http://richfaces.org/rich"
  xmlns:zanata="http://java.sun.com/jsf/composite/zanata">

  <script type="text/javascript"
    src="#{request.contextPath}/resources/script/components-script.js"></script>

  <script type="text/javascript">
    function selectItem(item) {
      window.location.href = jQuery(item).find('a').attr("href");
    }
  </script>

  <h1 class="header__title">
    <s:link view="/home.xhtml" propagation="none" id="home">
      <img class="header__site-logo"
        src="#{applicationConfiguration.webAssetsUrl}/logo.svg"/>
      #{msgs['jsf.Zanata']}
    </s:link>
  </h1>

  <nav id="nav-main" class="header__main-nav js-dropdown">
    <a href="#nav-main" class="header__main-nav__toggle js-dropdown__toggle">
      <i class="i i--huge i--list"></i>
      <span class="is-invisible">#{msgs['jsf.Menu']}</span>
    </a>

    <div class="header__main-nav__group js-dropdown__content">
      <h:form styleClass="form--search header__search js-form--search" id="general-search-form">
        <label class="form--search__label"
          for="#{rich:clientId('projectAutocomplete')}-autocomplete__input">
          #{msgs['jsf.SearchProjects']}
        </label>

        <zanata:autocomplete actionBean="#{projectSearch.projectAutocomplete}"
          maxlength="100" minlength="1" id="projectAutocomplete"
          fetchValue="#{result.project.slug}"
          placeholder="#{msgs['jsf.SearchProjects']}"
          onSelectItem="selectItem"
          inputClass="form--search__input js-form--search__input">

          <s:link propagation="none" view="/project/project.xhtml"
            rendered="#{!result.isProjectNull()}">
            <i class="i i--project"></i> #{result.project.name}
            <f:param name="slug" value="#{result.project.slug}"/>
          </s:link>

          <s:link view="/search.xhtml" rendered="#{result.isProjectNull()}">
            <i class="i i--search"></i> Search Zanata for
            '#{projectSearch.projectAutocomplete.query}'
            <f:param name="query" value="#{projectSearch.projectAutocomplete.query}"/>
          </s:link>

        </zanata:autocomplete>

      </h:form>
      <ul class="header__main-nav__menu">
        <li>
          <s:link id="projects_link" view="/project/home.xhtml"
            propagation="none">#{msgs['jsf.Projects']}
            <i class="is-hidden--m-up l--float-right i--inline i--project"></i>
          </s:link>
        </li>
        <li>
          <s:link id="version-groups_link" view="/version-group/home.xhtml"
            propagation="none">#{msgs['jsf.Groups']}
            <i class="is-hidden--m-up l--float-right i--inline i--group"></i>
          </s:link>
        </li>
        <li>
          <s:link id="languages_link" view="/language/home.xhtml"
            propagation="none">#{msgs['jsf.Languages']}
            <i class="is-hidden--m-up l--float-right i--inline i--language"></i>
          </s:link>
        </li>
        <s:fragment rendered="#{identity.loggedIn}">
          <li>
            <s:link id="glossary_link" view="/glossary/view.xhtml"
              propagation="none">#{msgs['jsf.Glossary']}
              <i
                class="is-hidden--m-up l--float-right i--inline i--glossary"></i>
            </s:link>
          </li>
        </s:fragment>

        <li>
          <s:link id="help_link" view="/help/view.xhtml"
            propagation="none">#{msgs['jsf.Help']}
            <i class="is-hidden--m-up l--float-right i--inline i--help"></i>
          </s:link>
        </li>
      </ul>
    </div>
  </nav>

  <s:fragment
    rendered="#{identity.loggedIn and authenticatedAccountHome.instance.enabled}">
    <nav class="header__user-nav js-dropdown">
      <a href="#nav-user" class="header__user-nav__toggle js-dropdown__toggle"
        id="user--avatar"
        title="#{authenticatedAccountHome.instance.username}">
        <div class="badge__container">
          <div class="bx--round header__avatar">
            <img src="#{gravatarServiceImpl.getUserImageUrl(72)}"
              alt="#{authenticatedAccountHome.instance.person.name}"/>
          </div>
        </div>
      </a>
      <ul id="nav-user" class="header__user-nav__menu js-dropdown__content">
        <li>
          <s:link id="dashboard" view="/dashboard/home.xhtml"
            propagation="none">
            #{msgs['jsf.Dashboard']} <i
            class="l--float-right i--inline i--dashboard"></i>
          </s:link>
        </li>
        <s:fragment rendered="#{s:hasRole('admin')}">
          <li>
            <s:link id="administration" view="/admin/home.xhtml"
              propagation="none">
              #{msgs['jsf.Administration']} <i
              class="l--float-right i--inline i--admin"></i>
            </s:link>
          </li>
        </s:fragment>
        <li>
          <s:link id="right_menu_sign_out_link" view="/account/logout.seam"
            propagation="none">
            #{msgs['jsf.Logout']} <i
            class="l--float-right i--inline i--logout"></i>
          </s:link>
        </li>
      </ul>
    </nav>
  </s:fragment>

  <s:fragment rendered="#{not identity.loggedIn}">
    <s:div styleClass="header__login l--float-right">
      <s:link id="register_link_internal_auth" view="/account/register.xhtml"
        value="#{msgs['jsf.Signup']}"
        propagation="none" styleClass="is-hidden--s button"
        rendered="#{applicationConfiguration.internalAuth}"/>

      <s:fragment
        rendered="#{not applicationConfiguration.internalAuth and not empty applicationConfiguration.registerPath}">
        <a id="register_link" href="#{applicationConfiguration.registerPath}"
          class="is-hidden--s button">#{msgs['jsf.Signup']}</a>
      </s:fragment>

      <h:outputLink id="signin_link"
        value="#{request.contextPath}/account/sign_in?continue=#{urlUtil.getEncodedLocalUrl(request)}"
        propagation="none" styleClass="l--push-left-half button--primary"
        rendered="#{not applicationConfiguration.kerberosAuth}">
        #{msgs['jsf.Login']}
      </h:outputLink>

      <h:outputLink id="ksignin_link"
        value="#{request.contextPath}/account/klogin.seam?continue=#{urlUtil.getEncodedLocalUrl(request)}"
        propagation="none" styleClass="l--push-left-half button--primary"
        rendered="#{applicationConfiguration.kerberosAuth}">
        #{msgs['jsf.Login']}
      </h:outputLink>
    </s:div>
  </s:fragment>

</header>
